<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      let six = [
        { name: '沈德亮', sex: '男', age: '23' },
        { name: '陈帅鹏', sex: '男', age: '22' },
        { name: '高嘉', sex: '男', age: '21' },
        { name: '陈志豪', sex: '男', age: '17' },
      ]
      // 封装函数
      function arrAy(){
        let arr = [
        `现有人员
            `,
      ]
      for (let i = 0; i <= six.length - 1; i++) {
        // 将six中的对象组成一句话存入arr数组
        arr.push(
          `姓名：${six[i].name}、年龄：${six[i].age}、性别：${six[i].sex}
            `
        )
      }
      // 使alert可以输出数组
      alert(arr.join('\
        '))
      }
      // 循环弹窗
      while (true) {
        let num = +prompt(`请输入要进行的操作序号
    1.新增
    2.删除
    3.退出
    `)
        if (num === 1) { 
          let user = prompt('请输入名字')
          let gender = prompt('请输入性别')
          let Age = prompt('请输入年龄')
          six.push({ name: user, sex: gender, age: Age })
          arrAy()
        } else if (num === 2) { 
          let deleteid = prompt('输入删除人员姓名')
          for (let i = 0; i <= six.length - 1; i++) {
            if (deleteid === six[i].name) {
              six.splice([i], 1)
            }
          }
          arrAy()
        } else if (num === 3) {
          alert('退出')
          arrAy()
          break
        } else alert('请按规定输入')
      }
      // 定义现有人员数组，使数字中的每一项为一句话

      console.log(six)
    </script>
  </body>
</html>
